<?php
/*
**整理所有的方法
**2015-07-10 
**BY PZP
*/

include_once('/var/www/html/new/d/class/Terminal_Check_Socket.class.php');
include '/var/www/html/new/d/class/OrderSmsManual.class.php';

class AllFunction{
	public function __construct(){
		$this->inSide = new SoapClient(null,array(
						"location" => "http://localhost/open/openService/pft_insideMX.php",
						"uri" => "www.16u.com?ac_16u=16ucom|pw_16u=c33367701511b4f6020ec61ded352059|auth_16u=true")
		);

		$this->outSide = new SoapClient("http://112.124.14.164/open/openService/MXSE.wsdl",array('encoding' =>'UTF-8','cache_wsdl' => 0));

		$this->smsManual = new \PFT\SMS\OrderSmsManual($this->inSide);
	}

	//票付通订单号查询
	public function Select_PFTorder($order,$buyid=null){
		$pft_order = $this->inSide->Order_Globle_Search(
				0,$buyid,0,0,"",
				"","","","","",
				"","",$order,"",0,
				"","","",1,0,
				0,1,"","","",
				"","","","","",
				"","",1,"",""
		);
		$pft_order_xml =simplexml_load_string($pft_order);
		return $pft_order_xml;
	}

	//远端订单号查询
	public function Select_REMOorder($order,$buyid=null){
		$pft_order = $this->inSide->Order_Globle_Search(
				0,$buyid,0,0,"",
				"","","","","",
				"","","","",0,
				"","","",1,0,
				0,1,0,"","",
				"",$order,"","","",
				"","","","",""
		);
		$pft_order_xml =simplexml_load_string($pft_order);
		return $pft_order_xml;
	}

	//反查订单
	public function See_Code($salerid,$code){
		$r = $this->inSide->Code_Verify_Order($salerid,$code,'');
		return $r;
	}

	//反查重码订单
	public function See_Code_More($mid, $num, $lid){
		$r = $this->inSide->PFT_Order_Code($mid, $num, -1, $lid);
		return $r;
	}

	//票付通内部验证
	public function Check_terminal($UUsalerid,$UUcode,$actiontime){
		$r=$this->inSide->Terminal_Check_In($UUsalerid,$UUcode,$actiontime,"");
		return $r;
	}

	//取消订单
	public function Cancel_Order($order){
		$r = $this->inSide->Order_Change_Pro($order,0,-1,0,0,"","","");
		return $r;
	}

	//取消订单 and 修改
	public function Modify_Order($order,$num){
		$r = $this->inSide->Order_Change_Pro($order,$num,-1,0,0,"","","");
		return $r;
	}

	//票付通新终端验证方式
	public function Terminal_Check_In_Voucher($terminal_inum,$UUsalerid,$UUcode){
		$result = $this->tc->Terminal_Check_In_Voucher($terminal_inum,$UUsalerid,$UUcode);
		return $result;
	}

	//整合兼容验证
	public function Compatible_Check_IN($UUsalerid,$UUcode,$actiontime){
		$this->tc = Terminal_Check_Socket::connect();
		$sel = "select terminal,terminal_type from uu_land where salerid='$UUsalerid' limit 1";
		$GLOBALS['le']->query($sel);
		$GLOBALS['le']->fetch_assoc();
		$terminal_inum = $GLOBALS['le']->f('terminal');
		$terminal_type = $GLOBALS['le']->f('terminal_type');
		if($terminal_type == 0){
			$terminal = $this->inSide->Terminal_Check_In($UUsalerid,$UUcode,$actiontime,"");
			if(is_numeric($terminal)){
				return $terminal;
			}else{
				return 100;
			}
		}elseif($terminal_type == 1){
			$terminal = $this->tc->Terminal_Check_In_Voucher($terminal_inum,$UUsalerid,$UUcode,array("vMode"=>7)); //vMode 7外部系统验证，5自助机验证。vCmd 499绕过所有限制验证，498已过期验证
			if($terminal['state'] == 'fail'){
				return $terminal['code'];
			}else{
				return 100;
			}
		}
	}

	//短信二维码的拼接
	public function url_sms($n)
	{
		$na=array("u","l","5","4","3","2","1","y","s","t");
		$n=(string)$n;
		$s="";
		$len=strlen($n);
		for ($i=0;$i<$len;$i++){
			$s.=$na[$n{$i}];
		}
		return $s;
	}

	public function Unified_Check_IN($UUsalerid,$UUcode,$actiontime,$chkIns){
		$this->tc = Terminal_Check_Socket::connect();
		$sel = "select terminal,terminal_type from uu_land where salerid='$UUsalerid' limit 1";
		$GLOBALS['le']->query($sel);
		$GLOBALS['le']->fetch_assoc();
		$terminal_inum = $GLOBALS['le']->f('terminal');
		$terminal_type = $GLOBALS['le']->f('terminal_type');
		if($terminal_type == 0){
			$terminal = $this->inSide->Terminal_Check_In($UUsalerid,$UUcode,$actiontime,"");
			if(is_numeric($terminal)){
				return $terminal;
			}else{
				return 100;
			}
		}elseif($terminal_type == 1){
			$terminal = $this->tc->Terminal_Check_In_Voucher($terminal_inum,$UUsalerid,$UUcode,array("vMode"=>7,"vCmd"=>$chkIns,'vCheckDate'=>$actiontime)); //vMode 7外部系统验证，5自助机验证,3软终端验证。vCmd 499绕过所有限制验证，498已过期验证
			if($terminal['state'] == 'fail'){
				return $terminal['code'];
			}else{
				return 100;
			}
		}
	}

	//票付通查询动态价格(0供应价 1零售价)
	public function Get_price($UUpid,$UUplaytime,$type){
		$UUlprice = $this->inSide->get_Dynamic_Price_Merge(
				$UUpid,$UUplaytime,1,'','',$type,0);
		return $UUlprice;
	}

	//新票付通查询动态价格(ptype 0供应价 1零售价)
	public function Dynamic_Price_And_Storage($ac,$pid,$date,$ptype,$m){
		$UUprice = $this->inSide->Dynamic_Price_And_Storage($ac,$pid,$date,1,$ptype,1,$m);
		return $UUprice;
	}

	//修改资金
	public function PFT_Modify_Money($UUmid,$Debit,$action,$dmode,$dtype,$ptype,$ordern){
		$money = $this->inSide->PFT_Member_Fund_Modify(
				$UUmid,$UUmid,$Debit,$action,$dmode, $aid=NULL,$dtype, $ptype,$ordern);
		return $money;
	}

	//重发短信
	public function reSend_SMS_Global_PL($ordern,$aid,$fid){
		$sendsmd=$this->inSide->reSend_SMS_Global_PL($ordern,$aid,$fid);
		return $sendsmd;
	}

	//走鸿群通道发送短信，可传第三方凭证码
	public function HQ_send_sms($tel,$aid,$fid,$tid,$pid,$ordernum,$lid,$title,$num,$begintime,$vcode,$link){
		$this->smsManual->SetParam($tel,$aid,$fid,$tid,$pid,$ordernum,$lid);
		$sms_ret = $this->smsManual->SendWithVcode($title, $num, $begintime, "", $vcode, $link);
		return $sms_ret;
	}

	//更新远端订单号
	public function Remote_Ordernum($orderid,$reorder){
		// echo $reorder;exit;
		$updateRemote = $this->inSide->Remote_Ordernum_Update(serialize(array($orderid=>$reorder)));
		return $updateRemote;
	}

	//获取接口密码
	public function Create_Conn_REC($account,$dname){
		$outSidePWD=$this->inSide->Create_Conn_REC($account,$dname);
		return $outSidePWD;
	}

	//外部接口下单
	public function outSide_Submit($array){
		$submit = $this->outSide->__soapCall("PFT_Order_Submit",
				array(
						"ac"=>$array['account'],
						"pw"=>$array['password'],
						"in0"=>$array['lid'],
						"in1"=>$array['tid'],
						"in2"=>$array['remoorder'],
						"in3"=>$array['tprice'],
						"in4"=>$array['num'],
						"in5"=>$array['playtime'],
						"in6"=>$array['name'],
						"in7"=>$array['tel'],
						"in8"=>"",
						"in9"=>$array['sms'],
						"in10"=>$array['paystatus'],
						"in11"=>0,
						"in12"=>"",
						"in13"=>$array['tuanhao'],
						"in14"=>0,
						"in15"=>0,
						"in16"=>$array['aid'],
						"in17"=>$array['IDcard']
				)
		);
		return $submit;
	}

	public function logfile($word,$path){
		$filepath= '/var/www/html/new/d/logs/api/api_order_Dynamic/'.$path.'.txt';
		$word = date("Y-m-d H:i:s")."|".$word.".";
		if(file_exists($filepath)){
			$maxsize  = 1024*1024*10;
			$filesize = filesize($filepath);
			$tmp=explode(".",$filepath);
			$filetype = end($tmp);
			$filename = substr($filepath,0,strpos($filepath,'.'));
			if($filesize>$maxsize)
				rename($filepath, $filename.'_'.date('YmdHis').'.'.$filetype);
		}
		$fp = fopen($filepath,"a");
		flock($fp, LOCK_EX);
		fwrite($fp,$word."\n");
		flock($fp, LOCK_UN);
		fclose($fp);
	}


}
// $PFT_infunction = new AllFunction();
// $order = $PFT_infunction->Select_PFTorder('1399049');
// $order = $PFT_infunction->Select_REMOorder('160473054171000000');
// $order =  $PFT_infunction->Remote_Ordernum(1550861,"cyt_20150721999000359");
// print_r($order);

?>
